-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Attempt to extend generated audio to fit captions gaps: extend voice breaks after commas #1
base: main
Are you sure you want to change the base?
Conversation
caption_end_time = caption_end(caption) | ||
diff = ((caption_end_time - caption_start_time) - audio_duration).__round__(3) | ||
result = '' | ||
split_caption = caption.text.split(',') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tu dzielimy każdy caption przecinkami
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
potem można by pomyśleć o uwzględnieniu innych znaków interpunkcyjnych i nadaniu im różnych wag.
Np przecinek to średnia przerwa, myślnik krótka, kropka długa.
for idx, cpt in enumerate(split_caption): | ||
result = result + cpt | ||
if idx != len(split_caption): | ||
result = result + '<break time="{}ms"/>'.format(define_break(diff, len(split_caption) - 1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jeśli to nie jest ostatnia część "captiona" doklejamy tag ciszy o konkretnej długości obliczonej przez define_break
@@ -80,6 +113,8 @@ def load_captions(config): | |||
print(f'Processing {caption}') | |||
sentence_audio = synthesize(caption.text, config) | |||
|
|||
sentence_audio = extend_sentence_audio(sentence_audio, caption) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Przekazujemy już wygenerowane zdanie (potrzebna nam jest jego długość) żeby móc zdefiniować odpowiednio dobraną długość pauzy po przecinku
@@ -92,4 +127,4 @@ def load_captions(config): | |||
new_audio = mpe.AudioFileClip(f'output/{config.audio_file_name}') | |||
# new_audio = mpe.CompositeAudioClip([input_clip.audio, new_audio]) | |||
final_clip = input_clip.set_audio(new_audio) | |||
final_clip.write_videofile(f'output/{config.movie_file_name}') | |||
final_clip.write_videofile(f'output/output_{config.movie_file_name}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plik jest już w katalogu output więc nie ma sensu go prefixować
audio_duration = sentence_audio.duration_seconds | ||
caption_start_time = caption_start(caption) | ||
caption_end_time = caption_end(caption) | ||
diff = ((caption_end_time - caption_start_time) - audio_duration).__round__(3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
można to lekko zoptymalizowąc. Jeśli diff
< noticeable_difference (np: 0,25) to zaakceptuj bieżące audio
@@ -61,6 +67,33 @@ def load_captions(config): | |||
raise Exception('Unsupported subtitles format') | |||
|
|||
|
|||
# TODO figure out better way of defining break length | |||
def define_break(diff_length, num_of_pauses): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To jest jedyny fragment z którego zrozumieniem mam problem.
Jeśli mamy 2 sek różnicy (diff_length=2.0) oraz 3 przecinki (num_of_pauses=3) to domyślna długość pauzy wyniesie 0,66(6) sekundy.
Potem jest mapowanie:
Jeśli domyślna długośc pauzy jest za dluga (powyżej 2 sek) to przytnij do 1 sek
Jeśli domyślna długośc pauzy jest między 1 a 2 sek to przytnij do 0,8 sek
Jeśli domyślna długośc pauzy jest poniżej 1 sek to przytnij do 0,5 sek
Dlaczego jest potrzebne to mapowanie? Dlaczego nie można po prostu zwrócić length_of_pause?
caption_end_time = caption_end(caption) | ||
diff = ((caption_end_time - caption_start_time) - audio_duration).__round__(3) | ||
result = '' | ||
split_caption = caption.text.split(',') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
potem można by pomyśleć o uwzględnieniu innych znaków interpunkcyjnych i nadaniu im różnych wag.
Np przecinek to średnia przerwa, myślnik krótka, kropka długa.
Dorzuciłem komentarze do poszczególnych fragmentów kodu. Daj znać jak coś jeszcze będzie niejasne :)